package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.SmsFlashPromotionProductRelationMapper;
import com.mall.model.domain.SmsFlashPromotionProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xyiaao
 * @description 针对表【sms_flash_promotion_product_relation(商品限时购与商品关系表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class SmsFlashPromotionProductRelationApiImpl extends ServiceImpl<SmsFlashPromotionProductRelationMapper, SmsFlashPromotionProductRelation>
        implements SmsFlashPromotionProductRelationApi {

    @Autowired
    private SmsFlashPromotionProductRelationMapper smsFlashPromotionProductRelationMapper;

    public Page<SmsFlashPromotionProductRelation> findBySms(Long flashPromotionId, Long flashPromotionSessionId, Integer pageNum, Integer pageSize) {

        Page<SmsFlashPromotionProductRelation> pageInfo = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsFlashPromotionProductRelation> lqw = new LambdaQueryWrapper<>();

        lqw.eq(flashPromotionId != null, SmsFlashPromotionProductRelation::getFlashPromotionId, flashPromotionId);
        lqw.eq(flashPromotionSessionId != null, SmsFlashPromotionProductRelation::getFlashPromotionSessionId, flashPromotionSessionId);
        lqw.orderByDesc(SmsFlashPromotionProductRelation::getSort);
        smsFlashPromotionProductRelationMapper.selectPage(pageInfo, lqw);
        return pageInfo;
    }

    @Override
    public void updateRelation(Integer id, SmsFlashPromotionProductRelation relation) {

        LambdaQueryWrapper<SmsFlashPromotionProductRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsFlashPromotionProductRelation::getId, id);
        smsFlashPromotionProductRelationMapper.update(relation, lqw);
    }

}




